﻿<!--#include virtual="/easyasp/easp.asp"-->
<%Response.CodePage = 65001
Response.Charset = "UTF-8"
subMode=3 '管理模式 1.指定IP   2.密码登录   3.双模
ips="219.138.237.7" '允许的IP列表，以半角逗号分隔
password="e779db654244bc8663c69b69588de58a" '密码登录模式，MD5加密后的密码

If Easp.Upload.GetData Then
	if Login()=1 then
	Dim File,F
	Easp.Upload.SavePath = "upfiles/"
	if Easp.Fso.IsExists("upfiles/")=false then Easp.Fso.CreateFolder("upfiles/")
	For Each File In Easp.Upload.Files("-1")
		Set F = Easp.Upload.Save(File,0,True)
		If F.Succeed Then
			'Easp.WN F.Path & F.FileName
			easp.echo "{""code"": 0 ,""msg"": """" ,""data"": {""src"": """&F.Path & F.FileName&"""}}"
		Else 
			Easp.WN F.Exception
		End If 
	Next
	end if
	easp.exit
End If

Easp.Rewrite "","^([0-9]+)?$","year=$1"
rootdir="/docs/" '文档根目录
temp="/template/" '模板目录
cache="/caches/" '缓存目录
current=easp.get("year") '当前文档年份
avatar="template/images/avatar.jpg" '头像
blogName="谢安夏的爸爸" '博名
blogMemo="职业篮球病运动员，业余IT民工" '简介
if easp.isN(current) then current=year(now)
dir=rootdir&current&"/"
if Easp.Fso.IsExists(dir)=false then Easp.Fso.MD(dir)
cache=cache&current&"/"
Easp.Fso.CharSet = "UTF-8"
searchKey=trim(easp.post("searchKey"))'搜索词

isLogin=Login()

if easp.post("logout")=1 then
	isLogin=0
	session.Abandon()
	easp.exit
end if

if easp.has(easp.post("data")) then
	if isLogin=1 then
		set j=Easp.Json.Parse(easp.post("data"))
		oldTitle=j("oldTitle")
		title=trim(j("title"))
		memo=easp.post("memo")
		if easp.isN(title) then
			easp.echo "layer.msg('标题不能为空！')"
		Else
			if easp.isN(oldTitle) Then'新增
				easp.fso.del cache
				easp.fso.createFile dir&title&".htm",memo
				easp.echo "window.location.reload()"
			else'编辑
				if oldTitle<>title then
					easp.fso.del dir&oldTitle&".htm"
				end if
				easp.fso.del cache
				easp.fso.createFile dir&title&".htm",memo
				easp.echo "window.location.reload()"
			end if
		end if
		'easp.wns jsons
	else
		easp.echo "isLogin=0;layer.closeAll();layer.alert('您无权限操作！')"
	end if
	easp.exit
end if

if easp.has(easp.post("password")) then
	if easp("md5").To32(easp.post("password"))=password then
		isLogin=1
		session("password")=password
		easp.echo "isLogin=1;layer.closeAll();layer.msg('登陆成功！')"
	else
		isLogin=0
		session.Abandon()
		easp.echo "isLogin=0;layer.msg('密码错误！')"
	end if
	easp.exit
end if

if easp.has(easp.post("fnames")) then
	fnameArr=split(easp.post("fnames"),"|||")
	if ubound(fnameArr)>0 then
		for i=0 to ubound(fnameArr)-1
			if easp.fso.isFile(dir&fnameArr(i)) then				
				Easp.echo "$(""li[fname|='"&fnameArr(i)&"'] em"").text('"&Easp.Str.JsEncode(Easp.Str.Cut(Easp.Str.HtmlFilter(Easp.Fso.Read(dir&fnameArr(i))),200))&"');"
			end if
		next
	else
		if easp.fso.isFile(dir&easp.post("fnames")) then
				Easp.echo Easp.Fso.Read(dir&easp.post("fnames"))
		end if
	end if
	easp.exit
end if

isMobile=isM()

if isMobile=true then
	tempFile="mindex.html"
	cachefile="mindex"
	else
	tempFile="index.html"
	cachefile="index"
end if


Set tpl = Easp.Tpl.New
tpl.FilePath = temp
if easp.fso.isFile(cache&cachefile) and easp.isN(searchKey) then
	Tpl.LoadStr easp.fso.read(cache&cachefile)
else
	flist=Easp.Fso.List(dir,1)
	dirlist=Easp.Fso.List(rootdir,2)	
	if easp.has(flist) then
		jsons="["
		for i=0 to ubound(flist,2)
			if easp.has(searchKey) then
				if Easp.Str.IsIn(flist(0,i),searchKey) then
					jsons=jsons&"{""title"":"""&flist(0,i)&""",""lastdate"":"""&flist(2,i)&"""}"
					if i<>ubound(flist,2) then jsons=jsons&","
				end if
			else
				jsons=jsons&"{""title"":"""&flist(0,i)&""",""lastdate"":"""&flist(2,i)&"""}"
				if i<>ubound(flist,2) then jsons=jsons&","
			end if		
		next
		jsons=jsons&"]"
		'easp.wns jsons
		flist=Easp.Encode(jsons)
	end if				
	tpl.load tempFile
	tpl "flist", flist		
	tpl "dir", dir
	tpl "current", current
	tpl "searchKey", searchKey
	for i=0 to ubound(dirlist,2)
		tpl "loop.year", Easp.Str.GetNameRev(dirlist(0,i), "/")
		tpl.Update "loop"
	next
	http=tpl.GetHtml()
	'easp.echo http
	if easp.has(http) and easp.isN(searchKey) then easp.fso.createFile cache&cachefile,http
end if
tpl "avatar", avatar
tpl "blogName", blogName
tpl "blogMemo", blogMemo
tpl "isLogin", isLogin	
tpl.show



Function Login()
	Login=0
	select case subMode
		case 1
			if easp.str.isinlist(ips,easp.getIP)=true then
				Login=1
			end if
		case 2
			if session("password")=password then
				Login=1
			end if
		case 3
			if session("password")=password or easp.str.isinlist(ips,easp.getIP)=true then
				Login=1
			end if
	end select
end Function

function isM()'是否移动端访问
		HTTP_ACCEPT=Request.ServerVariables("HTTP_ACCEPT")                 '获取浏览器信息
		HTTP_USER_AGENT=LCase(Request.ServerVariables("HTTP_USER_AGENT"))  '获取AGENT
		HTTP_X_WAP_PROFILE=Request.ServerVariables("HTTP_X_WAP_PROFILE")   'WAP特定信息 品牌机自带浏览器都会有
		HTTP_UA_OS=Request.ServerVariables("HTTP_UA_OS")                   '手机系统 电脑为空
		HTTP_VIA=LCase(Request.ServerVariables("HTTP_VIA"))                '网关信息
		Dim WapStr
		WAPstr=False
		If ubound(split(HTTP_ACCEPT,"vnd.wap"))>0 Then WAPstr=True
		If HTTP_USER_AGENT="" Then  WAPstr=True
		If HTTP_X_WAP_PROFILE<>"" Then  WAPstr=True
		If HTTP_UA_OS<>"" Then  WAPstr=True
		IF ubound(split(HTTP_VIA,"wap"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"netfront"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"iphone"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"opera mini"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"ucweb"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"windows ce"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"symbianos"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"java"))>0 Then  WAPstr=True
		IF ubound(split(HTTP_USER_AGENT,"android"))>0 Then  WAPstr=True
		isM=WAPstr
end function
%>